package com.ybf.api.mapper;

import com.ybf.api.entity.Role;
import com.ybf.api.mapper.provider.RoleProvider;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author ybf
 * @since 2024-09-26
 */
@Mapper
public interface RolesMapper {

    @SelectProvider(type = RoleProvider.class, method = "findAll")
    List<Role> list(@Param("role") Role role);

    @Delete("delete from roles where id = #{id}")
    Integer delete(@Param("id") Integer id);

    @Select("select intro, status, updated_at, created_at, id, role_name from roles where id = #{id}")
    Role info(@Param("id") Integer id);


    @Insert("insert into roles (role_name, intro, status) values (#{role.roleName}, #{role.intro}, #{role.status})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    Integer add(@Param("role") Role role);

    @Update("update roles set role_name = '${role.roleName}', intro = '${role.intro}', status = '${role.status}' where id = ${role.id}")
    Integer edit(@Param("role") Role role);
}
